<?php
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'list';
$return=array();
if($_RQ['op']=='list'){
	$pindex = max(1, intval($_SESSION['page']));
	$psize = 15;
	$params=array('uniacid'=>$_SESSION['uniacid']);
	if($_RQ['game_id']){
		$params['game_id']=intval($_RQ['game_id']);
		$return['params']['game_id']=$_RQ['game_id'];
	}
	//创建时间
	if($_RQ['createtime']){
		$time_range=cfc('tools')->base64_decode($_RQ['createtime'],$_SESSION['base_key_str']);
		$time_range=json_decode($time_range,true);
		$params['createtime between']=array($time_range['tstart'],$time_range['tend']);
		$return['params']['createtime']=$time_range;
	}
	$psize=20;
	$pindex=intval($_RQ['page'])?:1;
	$parameter=array(
		'params'=>$params,
		'limit'=>array($pindex,$psize),
		'orderby'=>'createtime desc',
		
	);
	$list=$this->get_list('coupon_log',$parameter,$total);
	if($list){
		foreach($list as &$item){
			$item['createtime']=date('Y-m-d H:i',$item['createtime']);
			$item['member']=pdo_get('core_members',array('uniacid'=>$_SESSION['uniacid'],'id'=>$item['mid']),array('from_os','nickname','avatar','mobile','sex','pcd'));
		}
	}
	$return['list']=$list;
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	$htmls=array(
		'type'=>'list',
		//'export'=>'export',
		'tabs'=>array(
			array('op'=>'list','title'=>'领取记录'),
		),
		'list'=>array('data'=>'list','tip'=>'<red>[温馨提示]：','delall'=>false,'list'=>array(
			array('name'=>'id','title'=>'ID','type'=>'string'),
			array('name'=>'member','title'=>'用户','type'=>'member'),
			array('name'=>'game_id','title'=>'所属活动','type'=>'select','options'=>'games'),
			array('name'=>'createtime','title'=>'创建时间','type'=>'time'),
		),'action'=>array(
		)),
		'search'=>array(
			array('name'=>'game_id','width'=>15,'title'=>'所属活动','type'=>'select','options'=>'games'),
			array('name'=>'createtime','width'=>15,'title'=>'创建时间','type'=>'time_range'),
		),
	);
	$return['games']=$this->pdo_getall('game',array('uniacid'=>$_SESSION['uniacid']));
	if($_SESSION['os']=='windows'){
		$return['htmls']=$htmls;
	}
	exi($return);
}
if($_RQ['op']=='del'){
	$id=intval($_RQ['id']);
	if(!$id){
		exi('请选择记录！！','error');
	}
	$del=trim($_RQ['del'],';');
	if($del){
		$del=explode(';',$del);
		foreach($del as $id){
			$id=intval($id);
			if($id){
				$this->pdo_delete('coupon_log',array('uniacid'=>$_SESSION['uniacid'],'id'=>$id));
			}
		}
	}
	exi('删除成功！');
}
?>